﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using NPSoft.Ferrero.DataBridge.Model;
using NPSoft.Ferrero.Framework.DAL;

namespace NPSoft.Ferrero.DataBridge.DAL
{
    public class HumanResourceUtil : IDAL<HumanResource>
    {
        public int Add(HumanResource info)
        {
            throw new NotImplementedException();
        }

        public int Edit(HumanResource info)
        {
            throw new NotImplementedException();
        }

        public HumanResource GetById(long id)
        {
            throw new NotImplementedException();
        }

        public HumanResource GetById(Guid id)
        {
            throw new NotImplementedException();
        }

        public int Remove(HumanResource info)
        {
            throw new NotImplementedException();
        }

        public System.Data.DataSet Search(StringBuilder condtion)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// SQL连接
        /// </summary>
        private SqlConnection Connection
        {
            get
            {
                return SqlHelper.GetConnection();
            }
        }

        public ICollection<HumanResource> SearchCollection(StringBuilder condtion)
        {
            ICollection<HumanResource> infos = new List<HumanResource>();
            StringBuilder sql = new StringBuilder();
            sql.Append(@"SELECT EMP_ID,DATA_SOURCE,HIRING_DATE,COMPANY_CD,EMPGRP_CD,EMPGRP_DESC
                ,PER_SUBAREA_CD,PER_SUBAREA_DESC,PER_SUBAREA_DESC_CHI,DEP_CD,DEP_DESC,POS_CD
                ,POS_DESC,ENG_TIL,CHI_TIL,ORG_UNIT_CD,ORG_UNIT_DESC,LOC_COS_CEN_CD,LOC_COS_CEN_DESC
                ,EMP_ENG_LAS_NM,EMP_ENG_FIR_NM,EMP_CHI_LAS_NM,EMP_CHI_FIR_NM,EMP_PY_LAS_NM,EMP_PY_FIR_NM
                ,GENDER,PER_MOB_PHO_NO,EMP_LINE_MGR_COMPANY_CODE,EMP_LINE_MGR_LOC_ID,EMP_LINE_MGR_LOC_ID2
                ,EMP_LINE_MGR_LOC_ID3,EMP_LINEMGR_FIR_NM,EMP_LINEMGR_LAS_NM,EMP_LINEMGR_POS_CD,EMP_LINEMGR_POS_DESC
                ,EMP_LINEMGR_USERID,EMP_LINEMGR_EMAILADDR,TERMINATION_DATE,USER_ID,COR_EMAIL_ADDR,VENDOR_CD,GRADE,IS_SALES,HR_POS_DESC FROM MST_EMPLOYEE");

            string sWhere = " where ";
            if (!string.IsNullOrEmpty(condtion.ToString()))
            {

                sql.Append(sWhere + condtion);
            }
            DataSet ds;
            ds = SqlHelper.ExecuteDataset(this.Connection, CommandType.Text, sql.ToString());
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                infos.Add(SetInfo(row));
            }
            return infos;
        }

        public HumanResource SetInfo(System.Data.DataRow row)
        {
            HumanResource humanresource = new HumanResource();
            humanresource.EMP_ID = SqlHelper.GetString(row, "EMP_ID");
            humanresource.DATA_SOURCE = SqlHelper.GetString(row, "DATA_SOURCE");
            humanresource.HIRING_DATE = SqlHelper.GetString(row, "HIRING_DATE");
            humanresource.COMPANY_CD = SqlHelper.GetString(row, "COMPANY_CD");
            humanresource.EMPGRP_CD = SqlHelper.GetString(row, "EMPGRP_CD");
            humanresource.EMPGRP_DESC = SqlHelper.GetString(row, "EMPGRP_DESC");
            humanresource.PER_SUBAREA_CD = SqlHelper.GetString(row, "PER_SUBAREA_CD");
            humanresource.PER_SUBAREA_DESC = SqlHelper.GetString(row, "PER_SUBAREA_DESC");
            humanresource.PER_SUBAREA_DESC_CHI = SqlHelper.GetString(row, "PER_SUBAREA_DESC_CHI");
            humanresource.DEP_CD = SqlHelper.GetString(row, "DEP_CD");
            humanresource.DEP_DESC = SqlHelper.GetString(row, "DEP_DESC");
            humanresource.POS_CD = SqlHelper.GetString(row, "POS_CD");
            humanresource.POS_DESC = SqlHelper.GetString(row, "POS_DESC");
            humanresource.ENG_TIL = SqlHelper.GetString(row, "ENG_TIL");
            humanresource.CHI_TIL = SqlHelper.GetString(row, "CHI_TIL");
            humanresource.ORG_UNIT_CD = SqlHelper.GetString(row, "ORG_UNIT_CD");
            humanresource.ORG_UNIT_DESC = SqlHelper.GetString(row, "ORG_UNIT_DESC");
            humanresource.LOC_COS_CEN_CD = SqlHelper.GetString(row, "LOC_COS_CEN_CD");
            humanresource.LOC_COS_CEN_DESC = SqlHelper.GetString(row, "LOC_COS_CEN_DESC");
            humanresource.EMP_ENG_LAS_NM = SqlHelper.GetString(row, "EMP_ENG_LAS_NM");
            humanresource.EMP_ENG_FIR_NM = SqlHelper.GetString(row, "EMP_ENG_FIR_NM");
            humanresource.EMP_CHI_LAS_NM = SqlHelper.GetString(row, "EMP_CHI_LAS_NM");
            humanresource.EMP_CHI_FIR_NM = SqlHelper.GetString(row, "EMP_CHI_FIR_NM");
            humanresource.EMP_PY_LAS_NM = SqlHelper.GetString(row, "EMP_PY_LAS_NM");
            humanresource.EMP_PY_FIR_NM = SqlHelper.GetString(row, "EMP_PY_FIR_NM");
            humanresource.GENDER = SqlHelper.GetString(row, "GENDER");
            humanresource.PER_MOB_PHO_NO = SqlHelper.GetString(row, "PER_MOB_PHO_NO");
            humanresource.EMP_LINE_MGR_COMPANY_CODE = SqlHelper.GetString(row, "EMP_LINE_MGR_COMPANY_CODE");
            humanresource.EMP_LINE_MGR_LOC_ID = SqlHelper.GetString(row, "EMP_LINE_MGR_LOC_ID");
            humanresource.EMP_LINE_MGR_LOC_ID2 = SqlHelper.GetString(row, "EMP_LINE_MGR_LOC_ID2");
            humanresource.EMP_LINE_MGR_LOC_ID3 = SqlHelper.GetString(row, "EMP_LINE_MGR_LOC_ID3");
            humanresource.EMP_LINEMGR_FIR_NM = SqlHelper.GetString(row, "EMP_LINEMGR_FIR_NM");
            humanresource.EMP_LINEMGR_LAS_NM = SqlHelper.GetString(row, "EMP_LINEMGR_LAS_NM");
            humanresource.EMP_LINEMGR_POS_CD = SqlHelper.GetString(row, "EMP_LINEMGR_POS_CD");
            humanresource.EMP_LINEMGR_POS_DESC = SqlHelper.GetString(row, "EMP_LINEMGR_POS_DESC");
            humanresource.EMP_LINEMGR_USERID = SqlHelper.GetString(row, "EMP_LINEMGR_USERID");
            humanresource.EMP_LINEMGR_EMAILADDR = SqlHelper.GetString(row, "EMP_LINEMGR_EMAILADDR");
            humanresource.TERMINATION_DATE=SqlHelper.GetString(row,"TERMINATION_DATE");
            humanresource.USER_ID=SqlHelper.GetString(row,"USER_ID");
            humanresource.COR_EMAIL_ADDR=SqlHelper.GetString(row,"COR_EMAIL_ADDR");
            humanresource.VENDOR_CD=SqlHelper.GetString(row,"VENDOR_CD");
            humanresource.GRADE=SqlHelper.GetString(row,"GRADE");
            humanresource.IS_SALES = SqlHelper.GetString(row, "IS_SALES");
            humanresource.HR_POS_DESC = SqlHelper.GetString(row, "HR_POS_DESC");

            return humanresource;
        }
    }
}
